package com.icode.core.dto.manager;

import com.icode.core.dto.house.MyHouseDTO;
import com.icode.core.model.house.Assignment;
import com.icode.core.model.house.MyHouse;
import com.icode.core.model.user.UserInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: sunk
 * Date: 15-11-15
 * Time: 下午10:03
 * To change this template use File | Settings | File Templates.
 */
public class AssignmentDTO {
    private String guid;
    private String myHouseGuid;
    private String houseImageGuid;
    private String description;

    private String userGuid;
    private String userImageGuid;
    private String userName;
    private String userPhone;
    private MyHouseDTO myHouseDTO;
    private String myHouseStatus;

    public AssignmentDTO() {
    }

    public AssignmentDTO(String guid, String myHouseGuid, String houseImageGuid, String description, String userGuid, String userImageGuid, String userName,MyHouseDTO myHouseDTO,String myHouseStatus,String userPhone) {
        this.guid = guid;
        this.myHouseGuid = myHouseGuid;
        this.houseImageGuid = houseImageGuid;
        this.description = description;
        this.userGuid = userGuid;
        this.userImageGuid = userImageGuid;
        this.userName = userName;
        this.myHouseDTO = myHouseDTO;
        this.myHouseStatus =myHouseStatus;
        this.userPhone = userPhone;
    }

    public String getMyHouseGuid() {
        return myHouseGuid;
    }

    public void setMyHouseGuid(String myHouseGuid) {
        this.myHouseGuid = myHouseGuid;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getGuid() {
        return guid;
    }

    public void setGuid(String guid) {
        this.guid = guid;
    }

    public String getHouseImageGuid() {
        return houseImageGuid;
    }

    public void setHouseImageGuid(String houseImageGuid) {
        this.houseImageGuid = houseImageGuid;
    }

    public String getUserGuid() {
        return userGuid;
    }

    public void setUserGuid(String userGuid) {
        this.userGuid = userGuid;
    }

    public String getUserImageGuid() {
        return userImageGuid;
    }

    public void setUserImageGuid(String userImageGuid) {
        this.userImageGuid = userImageGuid;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public MyHouseDTO getMyHouseDTO() {
        return myHouseDTO;
    }

    public void setMyHouseDTO(MyHouseDTO myHouseDTO) {
        this.myHouseDTO = myHouseDTO;
    }

    public String getMyHouseStatus() {
        return myHouseStatus;
    }

    public void setMyHouseStatus(String myHouseStatus) {
        this.myHouseStatus = myHouseStatus;
    }

    public String getUserPhone() {
        return userPhone;
    }

    public void setUserPhone(String userPhone) {
        this.userPhone = userPhone;
    }

    public static AssignmentDTO toDTO(Assignment assignment) {
        String guid = assignment.guid();
        String description = assignment.description();
        MyHouse myHouse = assignment.myHouse();
        UserInfo userInfo = myHouse.userInfo();
        String username = userInfo.username();
        String userImageGuid = userInfo.usersInfoImage().guid();
        String userGuid = userInfo.user().guid();
        String houseImageGuid = myHouse.houseInfo().houseInfoImages().get(0).image().guid();
        String myHouseGuid = myHouse.guid();
        MyHouseDTO myHouseDTO = MyHouseDTO.toDTO(myHouse);
        String myHouseStatus = assignment.myHouseStatus().getLabel();
        String userPhone =userInfo.user().getUsername();
        return new AssignmentDTO(guid, myHouseGuid, houseImageGuid, description, userGuid, userImageGuid, username,myHouseDTO,myHouseStatus,userPhone);
    }

    public static List<AssignmentDTO> toDTOs(List<Assignment> assignments) {
        List<AssignmentDTO> assignmentDTOs = new ArrayList<>();
        for (Assignment assignment : assignments) {
            assignmentDTOs.add(toDTO(assignment));
        }
        return assignmentDTOs;
    }
}
